﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LPV_POS;
using CrystalDecisions.CrystalReports.Engine;
using System.Windows.Forms;
using System.Data;

    public class Mod_baocao
    {
        xulyngaythangnam ngaythang;
        DataTable tb;
        thuvien tv;
        string[] s;
        object[] o;
        // select thong tin cong ty
        private DataTable f_selectgetinfo_company()
        {
            tv = new thuvien();
            s = new string[] { "@flag", "@CHOOSE" };
            o = new object[] { 1, 1 };
            tb = tv.SP_SelectDataTable("sp_mhcompany", s, o);
            return tb;
        }

        // ngay thang hien hanh
        private string f_chuoingayhienhanh()
        {
            string ngaythangnam = "";
            ngaythang = new xulyngaythangnam();
            tv = new thuvien();
            s = new string[] { "@flag", "@CHOOSE" };
            o = new object[] { 1, 1 };
            tb = tv.SP_SelectDataTable("sp_mhcompany", s, o);
            if (tb.Rows.Count > 0)
                ngaythangnam = ngaythang.chuoingay(tb.Rows[0]["NGAYHIENHANH"] + "");
            return ngaythangnam;
        }

        xulyngaythangnam ngaythangnam;
        public void report_common(ReportDocument rpt)
        {
            ngaythangnam = new xulyngaythangnam();
            xl_filetext filetext = new xl_filetext();
            filetext.f_readfiletext(Application.StartupPath + "\\baocao\\cauhinhbaocao.txt");
            if (Variable.str_tencongty_true.Trim() == "false")
            {
                Variable.str_tencongty = "";
            }
            if (Variable.str_masothuecongty_true.Trim() == "false")
            {
                Variable.str_masothuecongty = "";
            }
            if (Variable.str_diachicongty_true.Trim() == "false")
            {
                Variable.str_diachicongty = "";
            }
            if (Variable.str_chuky1_true.Trim() == "false")
            {
                Variable.str_chuky1 = "";
            }
            if (Variable.str_chuky2_true.Trim() == "false")
            {
                Variable.str_chuky2 = "";
            }
            if (Variable.str_chuky3_true.Trim() == "false")
            {
                Variable.str_chuky3 = "";
            }
            if (Variable.str_chuky4_true.Trim() == "false")
            {
                Variable.str_chuky4 = "";
            }
            if (Variable.str_chuky5_true.Trim() == "false")
            {
                Variable.str_chuky5 = "";
            }

            CrystalDecisions.CrystalReports.Engine.TextObject str_tencongty;
            str_tencongty = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_tencongty"];
            str_tencongty.Text = Variable.str_tencongty;    //"Doanh nghiệp: " + tb.Rows[0]["TENCONGTY"] + "";

            CrystalDecisions.CrystalReports.Engine.TextObject str_diachi;
            str_diachi = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_diachicongty"];
            str_diachi.Text = Variable.str_diachicongty;         //"Địa chỉ: " + tb.Rows[0]["DIACHI"] + "";

            CrystalDecisions.CrystalReports.Engine.TextObject str_masothue;
            str_masothue = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_masothuecongty"];
            str_masothue.Text = Variable.str_masothuecongty;                             //"Mã số thuế: ";     //tb.Rows[0]["MASOTHUE"] + "";       NGAYHIENHANH  txt_ngaythangnam

            CrystalDecisions.CrystalReports.Engine.TextObject str_ngaythangnam;
            str_ngaythangnam = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_ngaythangnam"];
            str_ngaythangnam.Text = ngaythangnam.chuoingay(ngaythangnam.chuyenngay(Variable.str_ngaythangnam));

            CrystalDecisions.CrystalReports.Engine.TextObject str_chuky1;
            str_chuky1 = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_nguoilapphieu1"];
            str_chuky1.Text = Variable.str_chuky1;

            CrystalDecisions.CrystalReports.Engine.TextObject str_chuky2;
            str_chuky2 = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_nguoilapphieu2"];
            str_chuky2.Text = Variable.str_chuky2;

            CrystalDecisions.CrystalReports.Engine.TextObject str_chuky3;
            str_chuky3 = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_nguoilapphieu3"];
            str_chuky3.Text = Variable.str_chuky3;

            CrystalDecisions.CrystalReports.Engine.TextObject str_chuky4;
            str_chuky4 = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_nguoilapphieu4"];
            str_chuky4.Text = Variable.str_chuky4;

            CrystalDecisions.CrystalReports.Engine.TextObject str_chuky5;
            str_chuky5 = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_nguoilapphieu5"];
            str_chuky5.Text = Variable.str_chuky5;
        }

        //-------------------------- Begin báo cáo lien quan den PDF -----------------------------------------
        public void f_header_report(ReportDocument CrReport)
        {

            tb = f_selectgetinfo_company();
            if (tb.Rows.Count > 0)
            {
                CrystalDecisions.CrystalReports.Engine.TextObject str_tencongty;
                str_tencongty = (CrystalDecisions.CrystalReports.Engine.TextObject)CrReport.ReportDefinition.ReportObjects["txt_tencongty"];
                str_tencongty.Text = "Doanh nghiệp: " + tb.Rows[0]["TENCONGTY"] + "";

                CrystalDecisions.CrystalReports.Engine.TextObject str_diachi;
                str_diachi = (CrystalDecisions.CrystalReports.Engine.TextObject)CrReport.ReportDefinition.ReportObjects["txt_dienthoaicongty"];
                str_diachi.Text = "Điện thoại: " + tb.Rows[0]["DIENTHOAI"] + "";

                CrystalDecisions.CrystalReports.Engine.TextObject str_dienthoai;
                str_dienthoai = (CrystalDecisions.CrystalReports.Engine.TextObject)CrReport.ReportDefinition.ReportObjects["txt_diachicongty"];
                str_dienthoai.Text = "Địa chỉ: " + tb.Rows[0]["DIACHI"] + "";

                //CrystalDecisions.CrystalReports.Engine.TextObject str_masothue;
                //str_masothue = (CrystalDecisions.CrystalReports.Engine.TextObject)CrReport.ReportDefinition.ReportObjects["txt_masothuecongty"];
                //if (tb.Rows[0]["MASOTHUE"] + "" != "")
                //    str_masothue.Text = "Mã số thuế: " + tb.Rows[0]["MASOTHUE"] + "";
                //else
                //    str_masothue.Text = "";

            }
            CrystalDecisions.CrystalReports.Engine.TextObject str_ngayinbaocao;
            str_ngayinbaocao = (CrystalDecisions.CrystalReports.Engine.TextObject)CrReport.ReportDefinition.ReportObjects["txt_ngaythangnam"];
            str_ngayinbaocao.Text = "In báo cáo " + f_chuoingayhienhanh();

          
        }

        //-------------------------- End báo cáo lien quan den PDF -----------------------------------------


    }

